<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>KityMinder Editor Lite</title>
    <link rel="stylesheet" href="./css/all.min.css" />
    <style>
        html, body {
            margin: 0;
            padding: 0;
            height: 100%;
            overflow: hidden;
        }
    </style>
</head>
<body ng-app="kityminderDemo" ng-controller="MainController">
    <kityminder-editor on-init="initEditor(editor, minder)"></kityminder-editor>
</body>
<script src="./js/all.min.js"></script>
<script>
	angular.module('kityminderDemo', ['kityminderEditor'])
			.controller('MainController', function($scope) {
				$scope.initEditor = function(editor, minder) {
					window.editor = editor;
					window.minder = minder;
				};
			});
    window.editorInit = function (success, error) {
        console.log('mindEditor.initEditor');
        if (!editor) {
            setTimeout(function () {
                window.initEditor();
            }, 100);
            return;
        }
        editor.minder.on("contentchange", function(e){
            console.log('mindEditor.editor.content.change');
            window.parent.postMessage({
                type: 'ContentChange',
                data: editor.minder.exportJson()
            }, '*');
        });
        success && success()
    };
    window.editorGetContent = function (success, error) {
        console.log('mindEditor.getEditorContent');
        if (!editor) {
            success(null)
            return
        }
        success(editor.minder.exportJson());
    };
    window.editorSetContent = function (success, error, content){
        console.log('mindEditor.setEditorContent', content);
        if (!editor) {
            return;
        }
        if(!content){
            content = {
                "root": {
                    "data": {"id": "byjpgvuzvv40", "created": 1574149619332, "text": "中心主题"},
                    "children": []
                }, "template": "default", "theme": "fresh-blue", "version": "1.4.43"
            };
        }
        editor.minder.importJson(content);
        success && success()
    };
    window.editorExport = function (success, error) {
        console.log('mindEditor.exportEditor');
        if (!editor) {
            success(null)
            return
        }
        editor.minder.exportData('svg').then(function (content) {
            let dom = $(content)
            dom.first('svg')[0].style.fontFamily = 'STHeitiSC-Light,STHeiti,Hei,"Heiti SC","Microsoft Yahei",Arial,sans-serif'
            success(dom[0].outerHTML);
        });
    };
</script>
</html>
